//
//  PictureCellTableViewCell.m
//  CarHome
//
//  Created by 王建男 on 14-9-25.
//  Copyright (c) 2014年 WJN_work@163.com. All rights reserved.
//

#import "PictureCellTableViewCell.h"
#import "UIImageView+WebCache.h"

@implementation PictureCellTableViewCell

- (void)dealloc
{
    [_scroll release];
    [_view release];
    _scroll = nil;
    _view = nil;
    [super dealloc];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self creatView];
    }
    return self;
}

- (void)awakeFromNib
{
    // Initialization code
}

#pragma mark -
#pragma mark creatView
- (void)creatView
{
    _view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 103)];
    [self.contentView addSubview:_view];
    
    _scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 90)];
    
    _scroll.delegate = self;
    [_scroll setShowsHorizontalScrollIndicator:NO];
    [_view addSubview:_scroll];
    
}

#pragma mark -
#pragma mark 设置数值

- (void)setImage:(NSMutableDictionary *)img
{
    
    _singletap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchBlock)];
    [_singletap setNumberOfTapsRequired:1];
    _singletap.delegate = self;
    [_scroll addGestureRecognizer:_singletap];
    
    NSMutableArray *imgArray = [img objectForKey:@"list"];
    CGFloat contentSize = 0;
    
    //便利数据数组 ， 将图片拼接成正常属性
    
    for (NSMutableDictionary *dic in imgArray) {
        
        NSMutableString *str = [NSMutableString stringWithFormat:@"%@", [dic valueForKey:@"smallpic"]];
        
        [str replaceOccurrencesOfString:@"s_" withString:@"m_" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [str length])];
        
        UIImageView *_imgView = [[UIImageView alloc] init];
        [_imgView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"Loading.png"]];
        [_imgView setUserInteractionEnabled:YES];
        
        
        _imgView.contentMode = UIViewContentModeScaleAspectFit;
        [_imgView setFrame:CGRectMake(contentSize, 0, 120, 90)];
        contentSize += (_imgView.frame.size.width + 3);
        
        [_scroll setContentSize:CGSizeMake(contentSize, 0)];
        
        [_scroll addSubview:_imgView];
        [_imgView release];
        
    }
    //downlabel
    UILabel *downview = [[UILabel alloc] initWithFrame:CGRectMake(0, 93, 320, 13)];
    [downview setText:[img objectForKey:@"name"]];
    [downview setFont:[UIFont systemFontOfSize:14]];
    [downview setTextAlignment:NSTextAlignmentCenter];
    [downview setTextColor:[UIColor colorWithWhite:0.6 alpha:1]];
    [_view addSubview:downview];
    [downview release];
}

- (void)touchBlock
{
    self.block();
}

#pragma mark -
#pragma mark block回调

- (void)sendReciveBlock:(PictureBlock )block
{
    self.block = block;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
